/*
 * @Description:  网址类型
 * @Author: Myruun
 * @Date: 2021-04-21 10:20:28
 * @LastEditors: Myruun
 * @LastEditTime: 2021-07-29 10:54:21
 * @FilePath: \serve\controller\resourceType.js
 */
const mysqlQuery = require('../unit/mysql.js');

// 获取网址类型列表
exports.Index = async (ctx, next) => {
	let body = ctx.request.body;
	const id = body.id || '';
	let sql = '';
	if (id) {
		sql =
			"SELECT * FROM resource_type  WHERE  id ='" +
			id +
			"' order by level desc";
	} else {
		sql = 'SELECT * FROM resource_type order by level desc';
	}
	let obj = await mysqlQuery(sql);
	ctx.response.body = obj;
};

// 添加网址类型
exports.add = async (ctx, next) => {
	let body = ctx.request.body;
	const title = body.title || '';
	const describe = body.describe || '';
	const level = body.level || 0;

	const time = Math.round(new Date() / 1000);
	let sql = `INSERT INTO resource_type (title, describes, level ) VALUES ('${title}','${describe}','${level}')`;
	let obj = await mysqlQuery(sql);
	ctx.response.body = { code: 200, data: { msg: '添加成功' } };
};
